package com.settlement.system.controller;

import com.settlement.system.common.enums.ReturnStatusEnum;
import com.settlement.system.common.exception.ServiceException;
import com.settlement.system.reply.ObjectDataResponse;
import com.settlement.system.service.IBaseService;
import com.settlement.system.common.util.common.FasUtil;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import com.settlement.system.model.entity.common.TblNcVurcherDetail;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;

import com.settlement.system.service.ITblNcVurcherDetailService;

import java.util.Map;

/**
 * NC凭证明细 前端控制器
 * @author Ximi
 * @since 2020-06-18
 */

@Slf4j
@Api(tags = "统一报表-NC凭证明细",description = "统一报表-NC凭证明细")
@RestController
@RequestMapping("/nc/vurcher-detail")
public class TblNcVurcherDetailController extends ExcelController<TblNcVurcherDetail> {

    @Resource
    private ITblNcVurcherDetailService tblNcVurcherDetailService;

    @Override
    public IBaseService init() {
        return tblNcVurcherDetailService;
    }

    @Override
    public Class<?> getModelClass() {
        return TblNcVurcherDetail.class;
    }

    @Override
    protected void setFootModel(Map<String, Object> result, Map<String, Object> model) throws ServiceException {
        result.put("foot",tblNcVurcherDetailService.getFoot(model));
    }

    @Override
    protected void setParamsModel(Map<String, Object> model) {
        FasUtil.formatInQueryCondition(model,"editorName","companyNo","unificationBillId");
        super.setParamsModel(model);
    }

    @ApiOperation("撤销NC")
    @RequestMapping(value = "revoke", method = {RequestMethod.POST})
    @ResponseBody
    protected ObjectDataResponse revokeNc(@RequestBody Map<String, Object> model, HttpServletRequest request) {
        try {
            FasUtil.formatInQueryCondition(model, "shopNo", "unificationBillId", "ncVirtualAccount", "originBillId", "companyNo");
            String message = tblNcVurcherDetailService.revokeNc(model);
            if (StringUtils.isEmpty(message)) {
                return new ObjectDataResponse(ReturnStatusEnum.REQUEST_SUCCESS);
            } else {
                return new ObjectDataResponse(ReturnStatusEnum.REQUEST_ABNORMAL.getValue(), message);
            }
        } catch (Exception ex) {
            log.info("更新数据异常", ex);
            return new ObjectDataResponse(ReturnStatusEnum.REQUEST_ABNORMAL);
        }
    }
}

